﻿using System.Web.Mvc;
using ENail.Domain.Core;
using ENail.Domain.Core.Contract.Services;
using ENail.Portal.Web.Models;
using Equation.Enterprise.Utilities.DesignByContract;

namespace ENail.Portal.Web.Controllers
{
    public class NailSalonController : BaseController
    {
        private readonly INailSalonService _nailSalonService;

        public NailSalonController(INailSalonService nailSalonService)
        {
            Check.Require(nailSalonService != null);

            _nailSalonService = nailSalonService;
        }

        [HttpGet]
        public ActionResult Index()
        {
            var user = (User) User;

            var nailSalon = new NailSalonViewModel();
            nailSalon.MapFromDomainModel(user.NailSalon);

            return View(nailSalon);
        }

        [HttpPost]
        public ActionResult Index(NailSalonViewModel model)
        {
            if (model == null)
                return Index();

            var user = (User) User;
            var nailSalon = _nailSalonService.GetBasicInformation(user.NailSalon.Id);
            model.MapToDomainModel(nailSalon);

            _nailSalonService.UpdateBasicInformation(nailSalon);

            user.NailSalon = nailSalon;

            return View(model);
        }
    }
}
